package com.mm.user.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mm.user.dao.UserMapper1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/9/18/018.
 */
@Service
public class UserService1 {

    @Autowired
    UserMapper1 mapper;

    public Map getList(Map map){
        Map maps = new HashMap();
        PageHelper.startPage(Integer.valueOf((String)map.get("pageNumber")), Integer.valueOf((String)map.get("pageSize")));
        List list = mapper.getList(map);
        PageInfo<Map> appsPageInfo = new PageInfo<>(list);
        int size = appsPageInfo.getSize();
        maps.put("data",list);
        maps.put("totalCount",size);
        return maps;
    }

    public void save(Map map) {
        String id = (String)map.get("id");
        if(StringUtils.isEmpty(id)){
            mapper.insert(map);
        }else{
            mapper.update(map);
        }
    }

    public void delete(Map reqMap) {
        mapper.delete(reqMap);
    }
}
